package com.example.aicooking.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.aicooking.entity.Post;
import com.example.aicooking.mapper.PostMapper;
import com.example.aicooking.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class PostServiceImpl implements PostService {
    
    @Autowired
    private PostMapper postMapper;
    
    @Override
    public List<Post> getRecommendPosts() {
        // 获取推荐帖子列表
        QueryWrapper<Post> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 20"); // 限制返回20条
        return postMapper.selectList(queryWrapper);
    }
    
    @Override
    public List<Post> getHotPosts() {
        // 获取热门帖子列表
        QueryWrapper<Post> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("like_count", "comment_count");
        queryWrapper.last("limit 20");
        return postMapper.selectList(queryWrapper);
    }
    
    @Override
    public List<Post> getFollowPosts(String userId) {
        // 获取关注的用户的帖子列表
        return postMapper.getFollowPosts(userId);
    }
}